﻿using Library.Common.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Synthesize.Common.Domain.Aggregation.ValueObject;
using Synthesize.Common.ServiceInterface.Dtos.Files;
using Synthesize.Common.ServiceInterface.UseCase;
using System.Threading.Tasks;

namespace SMS.UploadAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ApiExplorerSettings(GroupName = "Upload")]
    public class UploadController : ControllerBase
    {
        private readonly IUploadService _uploadService;
        public UploadController(IUploadService uploadService)
        {
            this._uploadService = uploadService;
        }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<UploadFileOutput>> UploadImage()
        {
            var result = await _uploadService.Upload(new UploadFileInput()
            {
                Files = Request.Form.Files,
                HomeFolder = Request.Headers["homeFolder"].ToString(),
                UploadType = UploadTypeEnum.Image
            });
            return result;
        }


        /// <summary>
        /// 常用文件上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<UploadFileOutput>> UploadFile()
        {
            var result = await _uploadService.Upload(new UploadFileInput()
            {
                Files = Request.Form.Files,
                HomeFolder = Request.Headers["homeFolder"].ToString(),
                UploadType = UploadTypeEnum.Default
            });
            return result;
        }

        /// <summary>
        /// 文档上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<UploadFileOutput>> UploadDocument()
        {
            var result = await _uploadService.Upload(new UploadFileInput()
            {
                Files = Request.Form.Files,
                HomeFolder = Request.Headers["homeFolder"].ToString(),
                UploadType = UploadTypeEnum.Document
            });
            return result;
        }
    }
}
